package facilius.controller.actionmanager;

import facilius.controller.ActionManager;
import facilius.controller.action.usuario.UsuarioCreateAction;
import facilius.controller.action.usuario.UsuarioDeleteAction;
import facilius.controller.action.usuario.UsuarioLoginAction;
import facilius.controller.action.usuario.UsuarioReadAction;
import facilius.controller.action.usuario.UsuarioShowFormAction;
import facilius.controller.action.usuario.UsuarioUpdateAction;
import org.mentawai.action.LogoutAction;
import org.mentawai.authorization.Permission;
import org.mentawai.core.ActionConfig;
import org.mentawai.core.ApplicationManager;
import org.mentawai.core.Forward;
import org.mentawai.core.Redirect;
import org.mentawai.filter.AuthorizationFilter;
import org.mentawai.filter.OVFilter;
import org.mentawai.filter.RedirectAfterLoginFilter;

/**
 *
 * @author Graciano
 */
public class UsuarioActionManager implements ActionManager {

    public void loadActions(ApplicationManager appManager) {
        ActionConfig ac = null;

        //login
        ac = new ActionConfig("Login", UsuarioLoginAction.class);
        ac.addConsequence(appManager.ERROR, new Forward("index.jsp"));
        ac.addConsequence("GR_ADMIN", new Redirect("UsuarioRead.mtw"));
        ac.addConsequence("GR_PROFESSOR", new Redirect("AulaRead.mtw"));
        ac.addConsequence("GR_ALUNO", new Redirect("EspacoNotaRead.mtw"));
        appManager.addActionConfig(ac);

//        ac.addFilter(new RedirectAfterLoginFilter());
//        ac.addConsequence(RedirectAfterLoginFilter.REDIR, new Redirect());

        //logout
        ac = new ActionConfig("Logout", LogoutAction.class);
        ac.addConsequence(appManager.SUCCESS, new Redirect("Login.mtw"));
        appManager.addActionConfig(ac);

        ac = new ActionConfig("UsuarioRead", UsuarioReadAction.class);
        ac.addConsequence(appManager.SUCCESS, new Forward("jsp/usuario/usuarioList.page"));
        ac.addConsequence(appManager.EXCEPTION, new Forward("jsp/erro.page"));
        ac.addFilter(new AuthorizationFilter(new Permission("usuario")));
        appManager.addActionConfig(ac);

        ac = new ActionConfig("UsuarioShowForm", UsuarioShowFormAction.class);
        ac.addConsequence(appManager.SUCCESS, new Forward("jsp/usuario/usuarioForm.page"));
        ac.addConsequence(appManager.ERROR, new Forward("jsp/erro.page"));
        ac.addFilter(new AuthorizationFilter(new Permission("usuario")));
        appManager.addActionConfig(ac);

        ac = new ActionConfig("UsuarioCreate", UsuarioCreateAction.class);
        ac.addConsequence(appManager.SUCCESS, new Redirect("UsuarioRead.mtw"));
        ac.addConsequence(appManager.ERROR, new Forward("jsp/erro.page"));
        ac.addFilter(new AuthorizationFilter(new Permission("usuario")));
        appManager.addActionConfig(ac);

        ac = new ActionConfig("UsuarioDelete", UsuarioDeleteAction.class);
        ac.addConsequence(appManager.SUCCESS, new Redirect("UsuarioRead.mtw"));
        ac.addConsequence(appManager.ERROR, new Forward("jsp/erro.page"));
        ac.addFilter(new AuthorizationFilter(new Permission("usuario")));
        appManager.addActionConfig(ac);

        ac = new ActionConfig("UsuarioUpdate", UsuarioUpdateAction.class);
        ac.addConsequence(appManager.SUCCESS, new Redirect("UsuarioRead.mtw"));
        ac.addConsequence(appManager.ERROR, new Forward("jsp/erro.page"));
        ac.addFilter(new AuthorizationFilter(new Permission("usuario")));
        appManager.addActionConfig(ac);
    }
}
